import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import path from "path"

export default defineConfig(({ command }) => {
	if (command === "serve") {
		return {
			plugins: [vue()],
			root: "example",
			server: {
				port: 3000
			},
			resolve: {
				alias: {
					"@": path.resolve(__dirname, "src")
				}
			}
		}
	} else {
		return {
			plugins: [vue()],
			build: {
				lib: {
					entry: path.resolve(__dirname, "src/index.js"),
					name: "OvertureUI",
					formats: ["es", "umd"],
					fileName: format => {
						if (format === "es") return "overture-ui.esm.js"
						if (format === "umd") return "overture-ui.umd.cjs"
					}
				},
				rollupOptions: {
					external: ["vue", "element-plus"],
					output: {
						globals: {
							vue: "Vue",
							"element-plus": "ElementPlus"
						},
						exports: "named"
					},
					treeshake: true
				},
				terserOptions: {
					compress: {
						drop_console: true,
						drop_debugger: true
					}
				},
				minify: "terser",
				sourcemap: false
			}
		}
	}
})
